package com.farsunset.ichat.cim.push;

import java.io.InputStream;

import com.appleframework.config.core.PropertyConfigurer;
import com.dbay.apns4j.IApnsService;
import com.dbay.apns4j.impl.ApnsServiceImpl;
import com.dbay.apns4j.model.ApnsConfig;

public class Apns4jServiceFactoryBean {
	
	private static IApnsService apnsService;
	
	public static IApnsService getApnsService(boolean isDev) {
		if (apnsService == null) {
			ApnsConfig config = new ApnsConfig();
			String path = PropertyConfigurer.getString("apns.certificate.path");
			String password = PropertyConfigurer.getString("apns.certificate.password");
			int poolsize = PropertyConfigurer.getInteger("apns.pool.size");
			InputStream is = Apns4jServiceFactoryBean.class.getClassLoader().getResourceAsStream(path);
			config.setKeyStore(is);
			config.setDevEnv(isDev);
			config.setPassword(password);
			config.setPoolSize(poolsize);
			apnsService = ApnsServiceImpl.createInstance(config);
		}
		return apnsService;
	}

}
